# Contributor: Manolis Tzanidakis
# Contributor: kevin <kevin@archlinux.org>
# Maintainer: 

pkgname=ifplugd
pkgver=0.28
pkgrel=17
pkgdesc="A daemon which brings up/down network interfaces upon cable insertion/removal."
arch=('x86_64')
url="http://0pointer.de/lennart/projects/ifplugd"
install=ifplugd.install
license=('GPL2')
depends=('libdaemon' 'bash')
backup=('etc/ifplugd/ifplugd.conf')
options=('!makeflags' '!emptydirs')
source=($url/${pkgname}-${pkgver}.tar.gz
        ifplugd-0.28-interface.patch
        ifplugd-fix-return-value.patch
        ifplugd-daemon
        ifplugd.systemd)
sha256sums=('474754ac4ab32d738cbf2a4a3e87ee0a2c71b9048a38bdcd7df1e4f9fd6541f0'
            '1bdbe17f26f467be2a5f300f20f2f8aa332ffa48cbe50bfc4bbff37de8f1bc67'
            'cbe50f373a30de95a7520f8084f99dac3f13ff9e73184877ed1add8ddcc2399e'
            'd69608997bb61d1deeec1525e9e7a018374875ad65ab39111c232210a43af47a'
            'f41b7a66a478652fa91a523c11943259a6e4b48b984dd314aca6309776533e83')

prepare() {
  cd ${pkgname}-${pkgver}
  patch -p0 -i ../ifplugd-0.28-interface.patch
  patch -p1 -i ../ifplugd-fix-return-value.patch
  sed 's|/var/run|/run|' -i src/ifplugd.c
}

build() {
  cd ${pkgname}-${pkgver}
  CFLAGS+=' -fcommon' # https://wiki.gentoo.org/wiki/Gcc_10_porting_notes/fno_common
  ./configure --prefix=/usr --sbindir=/usr/bin --mandir=/usr/share/man --sysconfdir=/etc \
      --with-initdir=/etc/rc.d --disable-xmltoman --disable-subversion --disable-lynx
  make
}

package() {
  cd ${pkgname}-${pkgver}
  make DESTDIR="${pkgdir}" install

  install -D -m755 "${srcdir}"/ifplugd-daemon "${pkgdir}"/usr/bin/ifplugd-daemon
  # remove the default init script and action script
  rm -f "${pkgdir}"/etc/{ifplugd/ifplugd.action,rc.d/ifplugd}
  # install systemd unit
  install -D -m644 "${srcdir}"/ifplugd.systemd "${pkgdir}"/usr/lib/systemd/system/ifplugd@.service
}
